package com.samapp.utils.json;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

/**
 * @author 梁建东
 * @date 2016/4/2
 * @lastModifyTime 2016/4/2
 */
public class NullStringToEmptyAdapterFactory<T> implements TypeAdapterFactory {
	@SuppressWarnings("unchecked")
	public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
		Class<T> rawType = (Class<T>) type.getRawType();
		if (rawType != String.class) {
			return null;
		}
		return (TypeAdapter<T>) new StringNullAdapter();
	}
}
